package com.jianggujin.redis.node;

import lombok.AllArgsConstructor;
import lombok.Getter;
import redis.clients.jedis.Jedis;

@Getter
@AllArgsConstructor
public class RedisKeys {
    private RedisDatabase database;
    private String item;

    @Override
    public String toString() {
        return item;
    }

    public RedisConnection getRedisConnection() {
        return database.getRedisConnection();
    }

    public Jedis getClient() {
        return getRedisConnection().getClient();
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((item == null) ? 0 : item.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        RedisKeys other = (RedisKeys) obj;
        if (item == null) {
            if (other.item != null)
                return false;
        } else if (!item.equals(other.item))
            return false;
        return true;
    }
}
